package se.sweco.gpsservice.datatypes;

public class GPSDataGPGSA {
	String GPSmode = "";
	String mode = "";
	String[] SVs = new String[12];
	float PDOP = 0.0f;
	float HDOP = 0.0f;
	float VDOP = 0.0f;
	String checksum = "";
	
	public void parseData(String data) {
		String[] gpsData = data.split(",");
		String gpsDataType = gpsData[0].substring(1);
		if(gpsDataType.equals("GPGSA")) {
			if(!gpsData[1].trim().equals(""))
				GPSmode = gpsData[1];
			if(!gpsData[2].trim().equals(""))
				mode = gpsData[2];
			//Up to 12 SV's
			for(int i = 3; i < gpsData.length - 3; i++) {
				if(!gpsData[i].trim().equals(""))
					SVs[i-3] = gpsData[i];
			}
			
			if(!gpsData[gpsData.length - 3].trim().equals(""))
				PDOP = new Float(gpsData[gpsData.length - 3]).floatValue();
			if(!gpsData[gpsData.length - 2].trim().equals(""))
				HDOP = new Float(gpsData[gpsData.length - 2]).floatValue();
			
			VDOP = new Float(gpsData[gpsData.length - 1].substring(0, gpsData[gpsData.length - 1].indexOf("*"))).floatValue();
			checksum = gpsData[gpsData.length - 1].substring(gpsData[gpsData.length - 1].indexOf("*"));
		}
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("GPSmode: ");
		if(GPSmode.equals("A")) sb.append(" Auto" + "\n");
		if(GPSmode.equals("M")) sb.append(" Manual" + "\n");
		sb.append("mode: ");
		if(mode.equals("1")) sb.append(" no fix" + "\n");
		if(mode.equals("2")) sb.append(" 2d fix" + "\n");
		if(mode.equals("3")) sb.append(" 3d fix" + "\n");
		
		for(int i = 0; i < SVs.length; i++) {
			if (SVs[i] != null)
				sb.append("Sv(" + i + ") " + SVs[i] + "\n");
		}
		
		sb.append("PDOP: " + PDOP + "\n");
		sb.append("HDOP: " + HDOP + "\n");
		sb.append("VDOP: " + VDOP + "\n");
		return sb.toString();
	}

	public String getGPSmode() {
		return GPSmode;
	}
	public void setGPSmode(String smode) {
		GPSmode = smode;
	}
	public String getMode() {
		return mode;
	}
	public void setMode(String mode) {
		this.mode = mode;
	}
	public String[] getSVs() {
		return SVs;
	}
	public void setSVs(String[] vs) {
		SVs = vs;
	}
	public float getPDOP() {
		return PDOP;
	}
	public void setPDOP(float pdop) {
		PDOP = pdop;
	}
	public float getHDOP() {
		return HDOP;
	}
	public void setHDOP(float hdop) {
		HDOP = hdop;
	}
	public float getVDOP() {
		return VDOP;
	}
	public void setVDOP(float vdop) {
		VDOP = vdop;
	}
	public String getChecksum() {
		return checksum;
	}
	public void setChecksum(String checksum) {
		this.checksum = checksum;
	}
}
